﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html xmlns:MSHelp="http://msdn.microsoft.com/mshelp">
    <head>
        <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
        <meta content="history" name="save">
        <title>SA1101: PrefixLocalCallsWithThis</title>
        <link rel="stylesheet" type="text/css" href="stylesheets/helpstudio.css"><link rel="stylesheet" type="text/css" href="styles/Presentation.css">
        <script src="script/helpstudio.js" type="text/javascript"></script>
        <script src="script/StandardText.js" type="text/jscript"></script>
    </head>
    <body id="hsbody">
        <input type="hidden" id="userDataCache" class="userDataStyle" name="userDataCache" />
        <div id="allHistory" class="saveHistory" onsave="saveScrollPosition()" onload="loadScrollPosition()"></div>
        <script type="text/jscript">WritePageTop(document.title);</script>
        <div id="pagebody">
            <div id="mainbody">
                <table>
                    <col />
                    <tr><td><p>TypeName</p></td><td><p>PrefixLocalCallsWithThis</p></td></tr>
                    <tr><td><p>CheckId</p></td><td><p>SA1101</p></td></tr>
                    <tr><td><p>Category</p></td><td><p>Readability Rules</p></td></tr>
                </table>           
                <h2>Cause</h2>
                <P>A call to an instance member of the local class or a base class is not prefixed with ‘this.’, within a C# code file.</P>
                <H2>Rule Description</H2>
                <P>A violation of this rule occurs whenever the code contains a call to an instance member of the local class or a base class which is not prefixed with ‘this.’. An exception to this rule occurs when there is a local override of a base class member, and the code intends to call the base class member directly, bypassing the local override. In this case the call can be prefixed with ‘base.’ rather than ‘this.’.</P>
                <P>By default, StyleCop disallows the use of underscores or <EM>m_</EM> to mark local class fields, in favor of the ‘this.’ prefix. The advantage of using ‘this.’ is that it applies equally to all element types including methods, properties, etc., and not just fields, making all calls to class members instantly recognizable, regardless of which editor is being used to view the code. Another advantage is that it creates a quick, recognizable differentiation between instance members and static members, which are not be prefixed.</P>
                <P>A final advantage of using the ‘this.’ prefix is that typing <EM>this.</EM> will cause Visual Studio to show the IntelliSense popup, making it quick and easy for the developer to choose the class member to call.</P>
                <H2>How to Fix Violations</H2>
                <P>To fix a violation of this rule, insert the ‘this.’ prefix before the call to the class member.</P>
                 <h2>How to Suppress Violations</h2>
                <pre>[SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1101:PrefixLocalCallsWithThis", Justification = "Reviewed.")]</pre>
            </div>
           <script type="text/jscript">WritePageFooter();</script> 
        </div>
    </body>
</html>